<?php

namespace App\Controller\Admin;
use App\Controller\ApiController;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Logger\LoggerFactory;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Logic\Admin\PermissionsLogic;
use Throwable;

class PermissionsController extends ApiController
{
    #[Inject]
    protected LoggerInterface $logger;
    #[Inject]
    protected PermissionsLogic $permissionsLogic;
    public function __construct(LoggerFactory $loggerFactory)
    {
        parent::__construct($loggerFactory);
        $this->permissionsLogic = new \App\Logic\Admin\PermissionsLogic();
    }

    /**
     * Notes:获取权限树
     * 2025/7/15
     * @return ResponseInterface
     * @throws \Exception
     */
    public function tree(): \Psr\Http\Message\ResponseInterface
    {
        try {
            $result = $this->permissionsLogic->tree();
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }
    public function list(): \Psr\Http\Message\ResponseInterface
    {
        try {
            $result = $this->permissionsLogic->list();
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }

    /**
     * Note:创建权限
     * User: Kong
     * Date: 2025/9/25
     * Time: 10:50
     * @return ResponseInterface
     * @throws \Exception
     */
    public function create(): \Psr\Http\Message\ResponseInterface
    {
        try {
            $result = $this->permissionsLogic->create($this->request->all());
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }

    /**
     * Note:更新权限
     * User: Kong
     * Date: 2025/9/25
     * Time: 11:11
     * @return ResponseInterface
     * @throws \Exception
     */
    public function edit(): \Psr\Http\Message\ResponseInterface
    {
        try {
            $result = $this->permissionsLogic->edit($this->request->all());
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }

    /**
     * Note:删除权限
     * User: Kong
     * Date: 2025/9/25
     * Time: 10:57
     * @return ResponseInterface
     * @throws \Exception
     */
    public function destroy(): \Psr\Http\Message\ResponseInterface
    {
        try {
            $result = $this->permissionsLogic->destroy($this->request->all());
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }
}